<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
  </head>
<body>
  <div class="nav">
    五子棋对战
  </div>
    <div class="login-container">
        <!-- 登陆界面的对话框 -->
         <div class="login-dialog">
            <!-- 提示信息 -->
             <h3>登陆</h3>
             <!-- 这个表示一行 -->
              <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
                </div>
                <!-- 这里表示另一行 -->
                 <div class="row">
                    <span>密码</span>
                    <input type="password" id="password">
                 </div>
                 <!-- 提交按钮 -->
                  <div class="row">
                    <button id="submit">提交</button>
                  </div>
              </div>
         </div>
    </div>

  <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
    <script>
        let submitButton = document.querySelector('#submit');
        submitButton.onclick = function() {
            // 1. 先获取到⽤⼾名和密码
            let username = document.querySelector('#username').value;
            let password = document.querySelector('#password').value;
            $.ajax({
                method: 'post',
                url: '/userController/login',
                data: {
                    username: username,
                    password: password
                },
                success: function(data) {
                    console.log(JSON.stringify(data));
                    if (data && data.userId > 0) {
                        // 登录成功, 跳转到游戏⼤厅
                    location.href = "/gobang_gamehall.html";
                  } else {
                      alert("登陆失败！")
                  }
          },
          error: function(){
            //请求失败后执行的回调函数
            alert("登陆失败请重新登陆！");
          }
        });
      }
    </script>
    
</body>
</html>